package com.sservice.banfu.controller;

import com.github.pagehelper.PageHelper;
import com.sservice.base.entity.dto.BaseResult;
import com.sservice.base.entity.dto.ListResult;
import com.sservice.base.utils.service.SService;
import com.sservice.commonBusiness.e.Statistic;
import com.sservice.commonBusiness.service.StatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by byte_su@163.com on 2018/02/05.
 * 统计信息
 */
@Controller
@RequestMapping("/admin/statistic/")
public class AdminStatistic1Controller {

    @Autowired
    StatisticService statisticService;


    @RequestMapping(value = "update-by-hand", method = RequestMethod.POST)
    @ResponseBody
    public BaseResult update(Statistic statistic) {
        Statistic statistic1 = statisticService.selectBy(statistic.getTargetId(), statistic.getType1());
        if ("device".equals(statistic.getType1())) { /// 设备评分修改
            statistic1.setScore(SService.genScore(statistic1.getScore(), statistic.getScore()));
        } else if ("teacher".equals(statistic.getType1())) {
            statistic1.setFavor(statistic.getFavor().add(statistic1.getFavor()));
            statistic1.setGuidance(statistic.getGuidance().add(statistic1.getGuidance()));
        } else if ("team".equals(statistic.getType1())) {
            statistic1.setFavor(statistic.getFavor().add(statistic1.getFavor()));
            statistic1.setView(statistic.getView().add(statistic1.getView()));
        }
        return new BaseResult(true, statisticService.updateByPrimaryKeySelective(statistic1));
    }

    @RequestMapping("list")
    @ResponseBody
    public ListResult list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
//        List<Statistic> list = statisticService.findAll();
//        PageInfo pageInfo = new PageInfo(list);
//        return new ListResult(true, pageInfo);
        return null;
    }
}
